package com.may.wind.entity;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 菜单信息
 */
@Entity
@Table(name = "menus")
@JsonIgnoreProperties({"handler", "hibernateLazyInitializer"})
@ApiModel(description = "菜单信息")
public class Menu implements Serializable {
    @Id
    @SequenceGenerator(sequenceName = "menu_sequence", name = "sequence_menus", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequence_menus")
    @Column(name = "id")
    @ApiModelProperty(name = "id", value = "ID", required = true)
    long id;
    @ApiModelProperty(name = "name", value = "菜单名称", required = true)
    String name;

    @ApiModelProperty(name = "path", value = "路径")
    String path;

    @ApiModelProperty(name = "nameZh", value = "中文名")
    String nameZh;

    @ApiModelProperty(name = "iconCls", value = "图标样式")
    String iconCls;

    @ApiModelProperty(name = "component", value = "组件")
    String component;

    @ApiModelProperty(name = "parentId", value = "父级菜单")
    long parentId;

    @Transient
    @ApiModelProperty(name = "children", value = "子菜单")
    List<Menu> children;

    /**
     * mapperBy为Role的menus属性
     */
    @ManyToMany(mappedBy = "menus", cascade = CascadeType.PERSIST, fetch = FetchType.EAGER)
    Collection<Role> roles = new ArrayList<>();

    public long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getNameZh() {
        return nameZh;
    }

    public void setNameZh(String nameZh) {
        this.nameZh = nameZh;
    }

    public String getIconCls() {
        return iconCls;
    }

    public void setIconCls(String iconCls) {
        this.iconCls = iconCls;
    }

    public String getComponent() {
        return component;
    }

    public void setComponent(String component) {
        this.component = component;
    }

    public long getParentId() {
        return parentId;
    }

    public void setParentId(long parentId) {
        this.parentId = parentId;
    }

    public List<Menu> getChildren() {
        return children;
    }

    public void setChildren(List<Menu> children) {
        this.children = children;
    }
}
